package com.shujia.sql

import com.google.gson.Gson

object Demo1Gson {
  def main(args: Array[String]): Unit = {

    val str = "{\"id\":\"1500100016\",\"name\":\"潘访烟\",\"age\":23}"

    //创建Gson对象
    val gson = new Gson()

    //将json字符串转换成一个自定义类的对象
    val person = gson.fromJson(str, classOf[Person])

    println(person)
    println(person.name)
    println(person.age)
    println(person.id)


  }

  //自定义类字段名和类型要和json字符串对应
  case class Person(id: String, name: String, age: Integer)

}
